package kr.hkit.androidcomplete01.chapter07;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

public class ToastTest extends Activity {
	int count;
	String str;
	Toast mToast;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch07_toastex);
	}

	public void mOnClick(View v) {
		switch (v.getId()) {
		case R.id.toastex_btn01:
			Toast.makeText(ToastTest.this, "잠시 나타나는 메시지", Toast.LENGTH_SHORT)
					.show();
			break;
		case R.id.toastex_btn02:
			Toast.makeText(ToastTest.this, "조금 길게 나타나는 메시지", Toast.LENGTH_LONG)
					.show();
			break;
		case R.id.toastex_btn03:
			str = "현재 카운트 = " + count++;
			if (mToast != null) {
				mToast.cancel();
			}
			mToast = Toast.makeText(ToastTest.this, str, Toast.LENGTH_SHORT);
			mToast.show();
			break;
		case R.id.toastex_btn04:
			str = "현재 카운트 = " + count++;
			if (mToast == null) {
				mToast = Toast
						.makeText(ToastTest.this, str, Toast.LENGTH_SHORT);
			} else {
				mToast.setText(str);
			}
			mToast.show();
			break;
		case R.id.toastex_btn05:
			LinearLayout linear = (LinearLayout) View.inflate(ToastTest.this,
					R.layout.ch07_toastview, null);
			Toast t2 = new Toast(ToastTest.this);
			t2.setView(linear);
			t2.show();
			break;
		}
	}
}
